<?php
namespace app\admin\controller;

use think\Db;
use app\admin\model\Member as user;
use think\Request;
use think\Validate;

class Member extends Main
{
    private $db;

    public function  __construct() {
        parent::__construct();
        $this->db = Db::name('member');
    }

    public function index()
    {
        $this->assign('item',['item1'=>'网站管理','item2'=>'会员列表']);
        return  $this->fetch();
    }

    public function get_table_data()
    {
        //获取分页page和limit参数
        $page=input("get.page")?input("get.page"):1;
        $page=intval($page);
        $limit=input("get.limit")?input("get.limit"):10;
        $limit=intval($limit);
        $start=$limit*($page-1);

        $count = $this->db->count("id");
        $data_list = $this->db->limit($start,$limit)->order('id desc')->select();
        $list["msg"]="";
        $list["code"]=0; //状态码
        $list["count"]=$count;
        $list["data"]=$data_list;
        if(empty($data_list)){
            $list["msg"]="暂无数据";
        }
        return json($list);
    }

    public function show_user()
    {
        $id = $this->request->get('id');
        if($id){
            $res = $this->db->where('id',$id)->find();
            $this->assign('data',$res);
            return  $this->fetch();
        }else{
            $this->error('非法操作');
        }
    }
}